package com.example.kafka.exception.consumer;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 处理消费者线程终止异常的Controller
 */
@RestController
@RequestMapping("/api/consumer-exception")
@RequiredArgsConstructor
public class ConsumerExceptionController {

    private final ConsumerExceptionService consumerExceptionService;

    /**
     * 用例1: 模拟反序列化异常
     */
    @PostMapping("/deserialization-error")
    public ResponseEntity<String> testDeserializationError(@RequestBody String message) {
        return ResponseEntity.ok(consumerExceptionService.handleDeserializationError(message));
    }

    /**
     * 用例2: 模拟数据库连接异常
     */
    @PostMapping("/db-connection-error")
    public ResponseEntity<String> testDbConnectionError(@RequestBody String message) {
        return ResponseEntity.ok(consumerExceptionService.handleDbConnectionError(message));
    }

    /**
     * 用例3: 模拟网络超时异常
     */
    @PostMapping("/network-timeout")
    public ResponseEntity<String> testNetworkTimeout(@RequestBody String message) {
        return ResponseEntity.ok(consumerExceptionService.handleNetworkTimeout(message));
    }

    /**
     * 用例4: 模拟内存溢出异常
     */
    @PostMapping("/out-of-memory")
    public ResponseEntity<String> testOutOfMemory(@RequestBody String message) {
        return ResponseEntity.ok(consumerExceptionService.handleOutOfMemory(message));
    }

    /**
     * 用例5: 模拟线程中断异常
     */
    @PostMapping("/thread-interrupt")
    public ResponseEntity<String> testThreadInterrupt(@RequestBody String message) {
        return ResponseEntity.ok(consumerExceptionService.handleThreadInterrupt(message));
    }
} 